<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\User;

class UserController extends Controller
{


    public function getUser(){
        $users = User::where('id',5)->get();
//         $new_user = $users->avg('id');
//         $new_user = $users->chunk(2);//拆分
//        $new_user = $new_user->collapse(); //合并两个为一个
//        $new_user = $users->concat(['id'=>5,'name'=>'xia']);
//        $new_user = $users->contains('name','Josh Rowe'); // 返回值：1


       /* $new_user = $users->contains(function ($value,$key){
            info($key);
            info(json_encode($value));
        }); //循环执行匿名函数中的判断*/

       /*$new_user = $users->each(function (){

       });*/
      /* $new_user = $users->flatmap(function ($val){

       });*/
//      $new_user = $users->flatten(2);

//        $new_user = $users->pluck('name','id'); //第一个为给定键的所有的值，第二个为生成集合的键


//        $new_user = $users->slice(1,2);//第一个设置索引，返回从该索引开始的后面的部分，第二个参数设置返回的长度


        /*$users = collect([5,2,43,1,7]);
        $new_user = $users->sort();//该数组中，默认是从0开始的，所以使用sort方法，会显示出来索引，并使用索引来排序，但是我可能想对这个值进行排序，那就使用values方法,将键重置为连续编号的索引
        $new_user = $users->sort()->values();*/

    /*    $users = collect([
            ['name' => 'Desk', 'price' => 200],
            ['name' => 'Chair', 'price' => 100],
            ['name' => 'Bookcase', 'price' => 150],
        ]);

        $new_user = $users->sortBy('price');
        $new_user = $new_user->values();*/

    $new_user = $users->map(function ($val){
        return $val->name.'11111';
    });



         return $new_user;

    }

}
